package com.example.demo.dao.daolmpl;



import com.example.demo.dao.UserDaoInterface;
import com.example.demo.entity.User;
import com.example.demo.entity.UserMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class UserDao implements UserDaoInterface {

    @Resource
    UserMapper userMapper;

    @Override
    public User Login(String name, String pass) {
        return userMapper.Login(name,pass);
    }

    @Override
    public void update(String string1, String string2) {
        userMapper.Update(string1,string2);
    }

    @Override
    public User selectNE(String string1, String string2) {
        return userMapper.selectNE(string1,string2);
    }

    @Override
    public List<User> select() {
        return userMapper.select();
    }

    @Override
    public int insert(User user) {
        return userMapper.insert(user);
    }

    @Override
    public String selectEmail(int mainIds) {
        return userMapper.selectEmail(mainIds);
    }

    @Override
    public User selectUser(String eamil) {
        return userMapper.selectUser(eamil);
    }
//
//    @Resource
//    private UserMapper userMapper;
//
//	User userBean = null;
//    private String SQL ="";
//    //登录
//    public JSONArray login(String username, String password){
//        JSONArray array = new JSONArray();
//        User user=userMapper.login(username,password);
//        JSONObject jsonObj = new JSONObject();
//        jsonObj.put("id",user.getId());
//        jsonObj.put("name",user.getName());
//        jsonObj.put("pass",user.getPass());
//        jsonObj.put("head",user.getHead());
//        jsonObj.put("phone",user.getPhone());
//        array.add(jsonObj);
//        return array;
////        SQL = "select * from usertb where name = ? and pass = ?";
////        Connection connection = null;
////        PreparedStatement pstmt = null;
////        JSONArray array = new JSONArray();
////        try {
////            connection = (Connection) dao.DBDao.getConnection();
////            pstmt = (PreparedStatement) connection.prepareStatement(SQL);
////            //这里的意思将用户名和密码填到SQL语句的问号处
////            pstmt.setString(1, username);
////            pstmt.setString(2, password);
////            ResultSet rSet = (ResultSet) pstmt.executeQuery();//得到数据库的查询结果,一个数据集
////            //判断结果集是否有效
////            if(rSet.next()){
////                /*user = new User();
////                user.setUsername(rSet.getString("uname"));
////                user.setPassword(rSet.getString("password"));*/
////            	JSONObject jsonObj = new JSONObject();
////                jsonObj.put("id",rSet.getString("id"));
////           	    jsonObj.put("name",rSet.getString("name"));
////           	    jsonObj.put("pass",rSet.getString("pass"));
////           	    jsonObj.put("head",rSet.getInt("head"));
////                jsonObj.put("phone",rSet.getInt("phone"));
////                array.add(jsonObj);
////            }
////            System.out.print("array"+array);
////            rSet.close();
////            connection.close();
////            pstmt.close();
////        } catch (Exception e) {
////            // TODO: handle exception
////            e.printStackTrace();
////        }finally{
////            dao.DBDao.closeConnection(connection);
////        }
////        return array;
//    }
//
////    //验证用户名是否重复
////    public String checking(String username) {
////        SQL = "select * from usertb where name = ?";
////        Connection connection = null;
////        PreparedStatement pstmt = null;
////        String i="0";
////        try {
////            connection = (Connection) dao.DBDao.getConnection();
////            pstmt = (PreparedStatement) connection.prepareStatement(SQL);
////            //这里的意思将用户名和密码填到SQL语句的问号处
////            pstmt.setString(1, username);
////            ResultSet rs = (ResultSet) pstmt.executeQuery();//得到数据库的查询结果,一个数据集
////            //判断结果集是否有效
////            if (rs.next()) {
////                i="1";
////            }
////            rs.close();
////            connection.close();
////            pstmt.close();
////        }  catch (Exception e) {
////            // TODO: handle exception
////            e.printStackTrace();
////        }finally{
////            dao.DBDao.closeConnection(connection);
////        }
////        return i;
////    }
////
////
////    //注册
////    public void Register(String name, String pass,int head,int phone) {
////        SQL = "insert into usertb(name,pass,head,phone) values (?,?,?,?)";
////        Connection connection = null;
////        PreparedStatement pstmt = null;
////        try {
////            connection = (Connection) dao.DBDao.getConnection();
////            pstmt = (PreparedStatement) connection.prepareStatement(SQL);
////            //这里的意思将用户名和密码填到SQL语句的问号处
////            pstmt.setString(1, name);
////            pstmt.setString(2, pass);
////            pstmt.setInt(3,head);
////            pstmt.setInt(4,phone);
////            pstmt.executeUpdate();//得到数据库的查询结果,一个数据集
////            pstmt.close();
////            connection.close();
////        } catch (Exception e) {
////            // TODO: handle exception
////            e.printStackTrace();
////        }finally{
////            dao.DBDao.closeConnection(connection);
////        }
////    }
}
